package airthmetic.exercise.queue;

import java.util.Stack;

public class _232_用栈实现队列 {
    static class MyQueue {
        private Stack<Integer> leftStack;
        private Stack<Integer> rightStack;

        public MyQueue() {
            this.leftStack = new Stack();
            this.rightStack = new Stack();
        }

        public void push(int x) {
            leftStack.push(x);
        }
        public void move(){
            if(rightStack.isEmpty()){
                while(!leftStack.isEmpty()){
                    rightStack.push(leftStack.pop());
                }
            }
        }
        public int pop() {
            move();
            return rightStack.pop();
        }

        public int peek() {
            move();
            return rightStack.peek();
        }

        public boolean empty() {
            return leftStack.isEmpty() && rightStack.isEmpty();
        }
    }
}
